package de.baumann.browser.activitys.duobao

import android.content.Context
import android.content.Intent
import de.baumann.browser.R
import de.baumann.browser.adapter.CodeListAdapter
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.duobao.IDuoBaoSuccessView
import de.baumann.browser.present.duobao.DuoBaoSuccessPresenter
import de.baumann.browser.utils.TimeUtil
import kotlinx.android.synthetic.main.activity_buy_success.*
import kotlinx.android.synthetic.main.include_tool_bar_2.*

class BuySuccessActivity : BaseOdinActivity<IDuoBaoSuccessView, DuoBaoSuccessPresenter>(),IDuoBaoSuccessView {

    companion object {
        fun startBuySuccessActivity(context: Context, code: String, amount: String, number: String, hash: String) {
            context.startActivity(Intent(context, BuySuccessActivity::class.java).apply {
                putExtra("code", code)
                putExtra("amount", amount)
                putExtra("number", number)
                putExtra("hash", hash)
            })
        }
    }

    private lateinit var codeListAdapter: CodeListAdapter

    override fun getLayout(): Int {
        return R.layout.activity_buy_success
    }


    override fun getBackIcon(): Int {
        return R.drawable.ic_back
    }

    override fun getTitleText(): String {
        return "购买详情"
    }

    override fun initView() {
        initToolbar(commToolBar,commTitle)
        shijian.text = TimeUtil.getStringByFormat(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")
        qihao.text = intent.getStringExtra("code") + "期"
        jine.text = "购买金额:" + intent.getStringExtra("amount")
        fene.text = "购买份数:" + intent.getStringExtra("number")
        codeListAdapter = CodeListAdapter()
        codeList.adapter = codeListAdapter
    }

    override fun initData() {
        presenter?.check(intent.getStringExtra("hash"))
    }

    override fun createPresenter(): DuoBaoSuccessPresenter {
        return DuoBaoSuccessPresenter()
    }

    override fun createView(): IDuoBaoSuccessView {
        return this
    }

    override fun setCodeList(list: List<String>) {
        codeListAdapter.setNewData(list)
    }

}